home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbasicpg.zip / DESSERT.BAS < prev    next >
BASIC Source File  |  1989-08-31  |  2KB  |  48 lines

  1. ' DESSERT.BAS
  2. ' This program contains two logic errors.  Can you find them?
  3.                                       
  4.                                        ' declare GetData subprogram
  5. DECLARE SUB GetData (array$(), num%, totalCalories%)
  6.  
  7. CLS
  8.                                        ' print welcome message
  9. PRINT "Welcome to the Dessert Program!"
  10. PRINT                                  ' get user's name
  11. INPUT "Please enter your name:  ", userName$
  12. PRINT                                  ' get number of desserts
  13. PRINT "How many desserts would you like to enter, "; userName$;
  14. INPUT num%
  15. PRINT
  16.  
  17. DIM desserts$(num%)                    ' dimension string array
  18.                                    
  19. GetData desserts$(), num%, totalCalories%  ' call subprogram
  20.                                     
  21. PRINT "The following is a list of "; userName$; "'s favorite desserts:"
  22. PRINT
  23.  
  24. FOR i% = 1 TO num%
  25.     PRINT "   "; desserts$(i%)         ' print array contents
  26. NEXT i%
  27.  
  28. PRINT                                  ' print total number of calories
  29. PRINT "The list contains a total of";  '   with number in flashing red
  30. COLOR 20: PRINT totalCalories%; : COLOR 7
  31. PRINT "calories!"
  32.  
  33. END
  34.  
  35. SUB GetData (array$(), num%, totalCalories%)
  36.  
  37. ' The GetData subprogram gets dessert information from the user.
  38.  
  39. FOR i% = 1 TO num%     ' loop num% times (passed from main program)
  40.     INPUT "   Dessert name:  ", array$(num%)       ' get dessert name
  41.     INPUT "   Calories in dessert:  ", calories%   ' get calories
  42.     PRINT
  43.     totalCalories% = calories%                     ' keep running total
  44. NEXT i%
  45.  
  46. END SUB                ' return array$ and totalCalories% to main program
  47.  
  48.